﻿using SYJ.BLL;
using SYJ.Common.web;
using SYJ.IBLL;
using SYJ.Model;
using SYJ.Model.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace SYJ.Logic.Controllers.admin
{
   public class SysUserMgrController:BaseController
    {
       ISysUserBLL bll = new SysUserBLL();
       public ActionResult Index()
       {
           return View();
       }

       public ActionResult GetSysUserList(QueryModel query, string user_name)
       {
           long count = 0;
           if (!string.IsNullOrEmpty(user_name))
           {
               query.SqlWhere = " and user_name like ?title ";
               query.Param.Add("user_name" , "%" + user_name + "%" );
           }
           List<SysUser> list = bll.GetPage(query, out count);
           var respose = JsonLayuiGridData<SysUser>.Create(query, list, count, "");
           return Json(respose, JsonRequestBehavior.AllowGet);
       }
       [HttpGet]
       public ActionResult AddOrUp(int? id)
       {
           SysUser role = new SysUser();
           if (id != null)
           {
               role = bll.GetModel(Convert.ToInt32(id));
           }
           return View(role);
       }
       [HttpPost]
       public ActionResult AddOrUp(SysUser model)
       {
           if (model.id > 0)
           {
               return Json(bll.Update(model), JsonRequestBehavior.AllowGet);
           }
           else
           {
               return Json(bll.Insert(model), JsonRequestBehavior.AllowGet);
           }
       }

       public ActionResult Delete(int id)
       {
           bool delete = bll.Delete(new SysUser() { id = id });
           return Json(delete, JsonRequestBehavior.AllowGet);
       }
    }
}
